package com.zhuchaooasystem.adapter.holder;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.entity.OrderTrackEntity;
import com.zhuchaooasystem.utils.DisplayUtils;

/**
 * Created by zhangyajiang on 2017/1/16.
 */

public class OrderTrackHolder extends BaseViewHolder<OrderTrackEntity.ListNotesBean> {

    TextView tv_top_line, tv_content, tv_down_line, tv_more_line;

    ImageView imageView;

    RelativeLayout layout;

    private Resources resource;
    private ColorStateList csl;

    private int size;

    public OrderTrackHolder(ViewGroup itemView, int size) {
        super(itemView, R.layout.item_order_track_recycleview);

        this.size = size;

        tv_top_line = $(R.id.among_track_topline);
        tv_content = $(R.id.among_track_tv);
        tv_down_line = $(R.id.among_track_line);
        imageView = $(R.id.among_track_image);
        tv_more_line = $(R.id.among_more_line);

        layout = $(R.id.among_track_layout);

        resource = (Resources) itemView.getContext().getResources();
    }

    @Override
    public void setData(OrderTrackEntity.ListNotesBean data) {
        super.setData(data);

        if (size==1){
            tv_top_line.setVisibility(View.GONE);
            imageView.setVisibility(View.GONE);
            tv_more_line.setVisibility(View.GONE);
            tv_down_line.setVisibility(View.GONE);
            tv_content.setText(data.getNotes());
            csl = (ColorStateList) resource.getColorStateList(R.color.color_1E1D25);
            tv_content.setTextColor(csl);
        }else if (size>1){
            if (getDataPosition()==0){
                tv_top_line.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
                tv_more_line.setVisibility(View.VISIBLE);
                tv_down_line.setVisibility(View.VISIBLE);

                //计算下面的直线的高度
                layout.measure(0, 0);
                int height_title = DisplayUtils.dip2px(getContext(), 30);
                RelativeLayout.LayoutParams lp_tv = (RelativeLayout.LayoutParams) tv_down_line.getLayoutParams();

                lp_tv.height = layout.getMeasuredHeight() - height_title + 1;

                tv_down_line.setLayoutParams(lp_tv);

                tv_content.setText(data.getNotes());
                imageView.setBackgroundResource(R.drawable.ic_green_true);
                csl = (ColorStateList) resource.getColorStateList(R.color.color_1E1D25);
                tv_content.setTextColor(csl);
            }else if (getDataPosition()==size-1){
                tv_top_line.setVisibility(View.VISIBLE);
                imageView.setVisibility(View.VISIBLE);
                tv_more_line.setVisibility(View.GONE);
                tv_down_line.setVisibility(View.GONE);

                tv_content.setText(data.getNotes());
                imageView.setBackgroundResource(R.drawable.ic_gray_true);
                csl = (ColorStateList) resource.getColorStateList(R.color.color_7f7f7f);
                tv_content.setTextColor(csl);
            }else{
                tv_top_line.setVisibility(View.VISIBLE);
                imageView.setVisibility(View.VISIBLE);
                tv_more_line.setVisibility(View.VISIBLE);
                tv_down_line.setVisibility(View.VISIBLE);

                //计算下面的直线的高度
                layout.measure(0, 0);
                int height_title = DisplayUtils.dip2px(getContext(), 30);
                RelativeLayout.LayoutParams lp_tv = (RelativeLayout.LayoutParams) tv_down_line.getLayoutParams();

                lp_tv.height = layout.getMeasuredHeight() - height_title + 1;

                tv_down_line.setLayoutParams(lp_tv);

                tv_content.setText(data.getNotes());
                imageView.setBackgroundResource(R.drawable.ic_gray_true);
                csl = (ColorStateList) resource.getColorStateList(R.color.color_7f7f7f);
                tv_content.setTextColor(csl);
            }
        }
    }

}
